package com.zhihuishu.micro.course.helper;

import com.zhihuishu.toolkit.jedis.JedisHelper;

/**
 * 工程中使用Key统一生成
 * 
 * @author zhanglikun
 * @date 2016年4月19日 下午4:02:48
 */
public class RedisKeyHelper {

    public static final int DEFAULT_EXPIRE = 7200;

    /**
     * 生成课程主键缓存Key
     * 
     * @param courseId
     * @return
     */
    public static final String courseKey(long courseId) {
        return JedisHelper.key("cc:course", courseId);
    }

    /**
     * app获取考核标准临时缓存
     */
    public final static String getTemporaryScoreAssessRuleKey(Long courseId) {
        return JedisHelper.key("cc", "temporary", "scoreAssessRule", courseId);
    }

    /**
     * 生成课程主键缓存Key
     * 
     * @param courseId
     * @return
     */
    public static final String getProgressInfoKey(long courseId) {
        return JedisHelper.key("cc:course", courseId, "progressInfo");
    }

    /**
     * 生成见面课主键缓存Key
     * 
     * @param courseId
     * @return
     */
    public static final String getMeetCourseIdKey(long courseId) {
        return JedisHelper.key("cc:course", courseId, "mcs");
    }

    /**
     * 生成见面课缓存key
     * 
     * @param courseId
     * @return
     */
    public static final String getMeetCourseKey(long meetcourseId) {
        return JedisHelper.key("cc:meetcourse", meetcourseId);
    }

    /**
     * 生成小节缓存key
     * 
     * @param courseId
     * @return
     */
    public static final String getlessonVideoKey(long lessonVideoId) {
        return JedisHelper.key("cc:lessonvideo", lessonVideoId);
    }

    
    /**
     * 生成小节缓存key
     * 
     * @param smallLessonId 小节id
     * @return
     */
    public static final String getSmallLessonKey(long smallLessonId) {
        return JedisHelper.key("cc:smallLesson", smallLessonId);
    }
    
    /**
     * 生成小节视频试题关联缓存key
     * 
     * @param lessonTestQuestionId 弹题关联信息id
     * @return
     */
    public static final String getlessonTestQuestionKey(long lessonTestQuestionId) {
        return JedisHelper.key("cc:lessontestquestion", lessonTestQuestionId);
    }
    
    /** 
     * 为满足学堂视频弹题的展示，海外的弹题的key与cc的key存储方式。暂时调整一致 
     * cc lessonTestKey start
     */
    
    //视频弹题打点信息key 格式如下：（00:00:01,00:00:02）
    //lessonId：节id 、lessonVideoId：小节id 
    public final static String getLessonTestQuestionTimerKey(Integer lessonId, Integer lessonVideoId) {
    	  
    	  if(lessonVideoId!=null) {//按照小节查询
        	  return String.format("cc:lessonTestQuestion:lessonVideoId:%s",lessonVideoId);

          }else {//按照节查询
        	  return String.format("cc:lessonTestQuestion:lessonId:%s",lessonId);

          }
    }
    
    //弹题Ids  Key 格式如下：（112080,112081）
    //lessonId：节id 、lessonVideoId：小节id 、timer：时间点
    public final static String getQuestionIds (Integer lessonId, Integer lessonVideoId, String timer) {
    	if (lessonVideoId!=null) {
    		return String.format("cc:quesIds:lessonId:%s:lessonVideoId:%s:timer:%s",lessonId,lessonVideoId,timer);
    	}
    	return String.format("cc:quesIds:lessonId:%s:lessonVideoId:%s:timer:%s",lessonId,"null",timer);
    }
    
    //获取小节的主键 ids(临时方案)
    public final static String getLessonTestionIds (Integer lessonId,Integer lessonVideoId,String timer,String questionId ) {
    	if (lessonVideoId!=null) {
    		return String.format("cc:lessonTestIds:lessonVideoId:%s:timer:%s:questionId:%s",lessonVideoId,timer,questionId);
    	}
    	return String.format("cc:lessonTestIds:lessonId:%s:timer:%s:questionId:%s",lessonId,timer,questionId);
    }
    
    /** 
     * 为满足学堂视频弹题的展示，海外的弹题的key与cc的key存储方式。暂时调整一致 
     * cc lessonTestKey end
     */
    
    

    /**
     * 生成教学团队主键缓存Key
     * 
     * @param courseId
     * @return
     */
    public static final String getCourseSpeakerIdsKey(long courseId) {
        return JedisHelper.key("cc:course", courseId, "courseSpeaker");
    }

    /**
     * 生成教学团队主键缓存Key
     * 
     * @param courseId
     * @return
     */
    public static final String getCourseSpeakerKey(Integer cskId) {
        return JedisHelper.key("cc:courseSpeaker", cskId);
    }

    /**
     * 新版和老版建课区分key
     */
    public final static String courseVersionKey(Long courseId) {
        return JedisHelper.key("cc", "version", "hash", courseId);
    }

    /**
     * 生成考核标准缓存key
     * 
     * @param courseId
     * @return
     */
    public static final String getScoreAssessRuleKey(long courseId) {
        return JedisHelper.key("cc:scoreAssessRule", courseId);
    }

    /**
     * 生成海外课程主键缓存Keys
     * 
     * @param courseId
     * @return
     */
    public static final String getCourseIdKeys(long userId) {
        return JedisHelper.key("cc:coursekey", userId, "treenity");
    }

    /**
     * 生成海外课程缓存key
     * 
     * @param courseId
     * @return
     */
    public static final String getCourseKey(long courseId) {
        return JedisHelper.key("cc:course", courseId, "treenity");
    }

    public static String getCourseChapterAllKey(long courseId) {
        return JedisHelper.key("cc:course", courseId, "chapters:all");
    }

    /**
     * 生成精彩视频redis缓存key
     * 
     * @param courseId
     * @return
     */
    public static final String getWonderVideoKey(long wonderVideoId) {
        return JedisHelper.key("cc:wondervideo", wonderVideoId);
    }

    /**
     * 一个课程下精彩视频id集合key
     * 
     * @param courseId
     * @return
     */
    public static final String getWonderVideoIdsKey(long courseId) {
        return JedisHelper.key("cc:wondervideo:ids", courseId);
    }
    //课程的更新信息id列表的key
    public static String getCourseTipSetKey(long courseId) {
        return JedisHelper.key("cc:tips", courseId);
        
    }
    //更新信息的详情的key
    public static String getTipInfoKey(Integer id) {
        // TODO Auto-generated method stub
        return JedisHelper.key("cc:tip", id, "info");
    }

    /**
     * 建课进度：已清理过redis缓存的见面课记录key
     *
     * @param courseId
     * @return
     */
    public static final String getCleanedMeetCourseKey(long meetcourseId) {
        return JedisHelper.key("cc:meetcourse:cleaned", meetcourseId);
    }
}
